<?php
	include_once "dataservice.php";
	
	class online_db
	{
		public function Them($SIDOnline, $TimeOut)
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "INSERT 	INTO 
								tbl_online(SIDOnline, TimeOut) 
								VALUES(" . dataservice::QuoteSmart($SIDOnline) . ", " . dataservice::QuoteSmart($now + $TimeOut). ")";
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function Count()
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "SELECT COUNT(*) NumOnline 
					   FROM tbl_online 
					   WHERE (1) and TimeOut >= " . $now;
			
			$db = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
		
		public function CapNhat($SIDOnline, $TimeOut)
		{
			$date = getdate();
			$now = $date[0];
			$sql = "UPDATE 	tbl_online 
					SET TimeOut = ".($now + $TimeOut) . " 
					WHERE SIDOnline = " . dataservice::QuoteSmart($SIDOnline);
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function Xoa()
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "DELETE FROM tbl_online WHERE (1) AND TimeOut < " . $now;
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function Check($SIDOnline)
		{
			$sql = "SELECT * FROM tbl_online WHERE (1) AND SIDOnline = " . dataservice::QuoteSmart($SIDOnline);
			
			$db  = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
	}
?>